#include <iostream>
using namespace std;

//泛型编程



// template <class T>
// void Swap(T& left,T& right)
// {
//     T temp = left;
//     left = right;
//     right = temp;
// }

// int main()
// {
//     int i =1,j = 2;
//     double x = 1.1,y = 2.2;
//     Swap<int)(i,j);//显式调用
//     Swap(x,y);
//     return 0;
// }

template <class T>
class Stack{
public:
    Stack(int capacity = 4)
    :m_capacity(capacity)
    {
        cout<<"Stack(int capacity = 4)"<<endl;
        m_array = new T[m_capacity];
        m_size = 0;
    }
    Stack(const Stack& ST)//栈需要完成深拷贝
    {
        m_array = new T[m_capacity = ST.m_capacity];
        m_size = ST.m_size;
    }
    void Push(T x)
    {
        m_array[m_size++] = x;
    }
    ~Stack()
    {
        cout<<"~Stack"<<endl;
        delete [] m_array;
        m_array = nullptr;
        m_size = 0;
        m_capacity = 0;
    }
private:
T *m_array;
int m_capacity;
int m_size = 0;
};


